package com.zzq.controller;

import com.zzq.mq.RocketmqProducer;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author iszengziqiang@163.com
 * @date 2020/10/22 16:55
 * @Version: 1.0
 * @desc //todo
 */
@RestController
public class RocketmqController {

    @Autowired
    RocketmqProducer rocketmqProducer;

    @GetMapping(value = "/sendMsg")
    public void sendMsg() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            rocketmqProducer.SyncProducer("发的消息是：" + sdf.format(new Date()));
        } catch (MQClientException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (RemotingException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (MQBrokerException e) {
            e.printStackTrace();
        }
    }

}
